# -*- coding: utf-8 -*-
# @Time : 2022-06-23 17:24
# @Author : Z
# @Function : 后台管理-餐桌管理
import json


from Keywords.inter_keys import Inter



inter = Inter()

# 设置系统地址
inter.set_url('https://pos3-test-gateway.bgyfoodom.com')

# # 后台登陆
# inter.post_json('/auth/systemV1/username-login',
#                 '{"password":"d8GWF69C1A3tOXjb2VP0EaSjgTOD5zF5lRn0Y/yCHJjXdD0XUm+lVmAIO4LMFivLKJkfSm9Rc1cHbWnsNQObRsgY1784HmpIxWCG7Lkf2Aazj8X06u5I5u4/YGRrENS5wgR3VLKGIJLeNcqC1amRqdQXxzsQHuDCcWMKpTPuApc=","name":"15678300490","channelId":"11"}')
# # 断言登陆成功
# inter.assert_equals('code', '0000')

# 运营APP登陆
inter.post_json('/auth/system/username-login',
                '{"password":"aA.11111","name":"15678300490","channelId":"11"}')
# 断言登陆成功
inter.assert_equals('code', '0000')

# 提取token
inter.save_json("$.data.accessToken", "newtoken")
# 添加authorization到请求头
inter.add_header('authorization', '{newtoken}')

# 查询堂食菜单
inter.post_json("/maintain/storage/chinese-food/product",'{"storeId":"1550313489139277827","orderTypeId":"1"}')
inter.assert_equals('code', '0000')
# inter.save_json('$.data[0].products[0].productId','productId')
# inter.save_json('$.data[0].products[0].productName','productName')
# inter.save_json('$.data[0].products[0].specs[0].specName','specName')
# inter.save_json('$.data[0].products[0].specs[0].productStorageId','productStorageId')
#
# # 获取菜品库存id
# inter.save_json('$.data[0].products[0].specs[0].specId','specId')
#
# # 查询预约菜单
# inter.post_json("/maintain/storage/chinese-food/product",
#                 '{"storeId":"1550313489139277827","orderTypeId":"2"}')
# inter.assert_equals('code', '0000')
#
# # 获取预约菜品做法
# inter.post_json("/maintain/storage/chinese-food/special-cook",
#                 '{"storeId":"1550313489139277827","orderTypeId":"2"}')
# inter.assert_equals('code', '0000')
#
# 堂食菜品沽清
# inter.post_json('/maintain/storage/chinese-food/product-spec/storage/save',
#                 '{"storeId": "1550313489139277827","productId": "{productId}","specId": "{specId}","storageQuantity": 15,"specName": "{specName}","productName": "{productName}","orderTypeId":"1"}')
# inter.assert_equals('code', '0000')
#
# # 菜品取消沽清
# inter.post_json('/maintain/storage/chinese-food/product-spec/storage/delete',
#                 '{"productStorageId": "{productStorageId}"}')
# inter.assert_equals('code', '0000')
#
# # 菜品沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/product-spec/storage/save',
#                 '{"storeId": "1550313489139277827","productId": "{productId}",'
#                 '"specId": "{specId}","storageQuantity": 15,"specName": "{specName}",'
#                 '"productName": "{productName}","orderTypeId":"1"}')
#
# # 清空菜品沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/product-spec/storage/clean',
#                 '{"storeId":"1550313489139277827","orderTypeId":"1"}')
# inter.assert_equals('code', '0000')
#
# # 菜品沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/product-spec/storage/save',
#                 '{"storeId": "1550313489139277827","productId": "{productId}",'
#                 '"specId": "{specId}","storageQuantity": 15,"specName": "{specName}",'
#                 '"productName": "{productName}","orderTypeId":"1"}')
# # 获取堂食菜品做法
# inter.post_json("/maintain/storage/chinese-food/special-cook",
#                 '{"storeId":"1550313489139277827","orderTypeId":"1"}')
# inter.save_json('$.data[0].specialCookId','specialCookId')
# inter.save_json('$.data[0].specialCookName','specialCookName')
# inter.assert_equals('code', '0000')
#
# # 做法沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/special-cook/storage/insert',
#                 '{"storeId":"1550313489139277827","specialCookId":"{specialCookId}","specialCookName":"{specialCookName}","orderTypeId":"1"}')
# inter.assert_equals('code', '0000')
# 获取做法信息-堂食
# inter.post_json("/maintain/storage/chinese-food/special-cook",
#                 '{"storeId":"1550313489139277827","orderTypeId":"1"}')
# inter.save_json('$.data[0].specialCookStorageId','specialCookStorageId')
#
# # 取消做法沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/special-cook/storage/delete',
#                 '{"specialCookStorageId": "{specialCookStorageId}"}')
# inter.assert_equals('code', '0000')
#
# # 做法沽清-堂食
# inter.post_json('/maintain/storage/chinese-food/special-cook/storage/insert',
#                 '{"storeId":"1550313489139277827","specialCookId":"{specialCookId}",'
#                 '"specialCookName":"{specialCookName}","orderTypeId":"1"}')
#
# # 清空做法沽清
# inter.post_json('/maintain/storage/chinese-food/special-cook/storage/clean',
#                 '{"storeId":"1550313489139277827","orderTypeId":"1"}')
# inter.assert_equals('code', '0000')
#
# # 订单列表
# inter.post_json('/maintain/order/chinese-food/page',
#                 '{"current": 1,"size": 15,"storeId": "1550313489139277827","tableId": "","orderType": 1,"typeId": 1}')
# inter.assert_equals('code', '0000')

# 获取订单id
# inter.save_json('$.data.records[0].id','orderId')

# for i in range(0, 10):
#     a = '$.data.records[' + str(i) + '].statusName'
#     inter.save_json(a, 'statusName')
#     if (inter.relations.get('statusName') == "已支付" or inter.relations.get('statusName') == "已完成"):
#         inter.save_json('$.data.records[' + str(i) + '].id', 'orderId')
#         # print(inter.relations.get("orderId"))
#         break
#     else:
#         inter.relations["orderId"] = None

# # 从数据库获取已支付，待处理的订单id
# inter.save_sql('select a.store_id,b.order_id,b.id,a.status_id,b.order_status_id,a.type_id from order_info a  inner join order_detail b on a.id=b.order_id where a.store_id="1550313489139277827" and b.order_status_id=21 and a.status_id=32',
#                "order_id")



# # 预约订单列表
# inter.post_json('/maintain/order/chinese-food/page',
#                 '{"current": 1,"size": 15,"storeId": "1550313489139277827","tableId": "","orderType": 1,"typeId": 5}')
# inter.assert_equals('code', '0000')


# # 订单详情
# inter.post_json('/maintain/order/chinese-food/detail', '{"orderId": "{order_id}"}')
# inter.assert_equals('code', '0000')
# inter.save_json('$.data.productList[0].orderStatusName', 'orderStatusName')
# if inter.relations.get("orderStatusName") == "退款中":
#     inter.save_param('orderDetailIdList', "None")
#     print("系统bug，退款失败，状态一直是“退款中”")

# ll = []
# for i in range(0, 100):
#     aa = inter.save_json('$.data.productList[' + str(i) + '].id', 'orderDetailIdList' + str(i))
#     if aa.get('orderDetailIdList' + str(i)) == 'None':
#         inter.relations.pop('orderDetailIdList' + str(i))
#         break
#     else:
#         ll.append(inter.relations.get('orderDetailIdList' + str(i)))
# print(ll)
# bb = str(ll).replace("'", '"')
#
# inter.save_param('orderDetailIdList', bb)
# # a = inter.relations
# # print(a)

# 从数据库获取已支付，待处理的订单详情ID组
# inter.save_sql('select a.store_id,b.order_id,b.id,a.status_id,b.order_status_id,a.type_id from order_info a  inner join order_detail b on a.id=b.order_id where a.store_id="1550313489139277827" and b.order_status_id=21 and a.status_id=32',
#                "id")
# # 订单操作-退款
# inter.post_json('/maintain/order/chinese-food/update',
#                 '{"type":"1","orderId":{order_id},"remark":"","orderDetailIdList":["{id}"]}')
# inter.assert_equals('code', '0000')

# # 不传订单详情ID组
# inter.post_json('/maintain/order/chinese-food/update',
#                 '{"type":"1","orderId":{order_id},"remark":""}')
# inter.assert_equals('code', '0000')


# 正常新增餐桌
# inter.post_json("/manager/store/page", '{"size":10,"current":1,"cityId":"","name":"测试门店-zwx"}')
# inter.save_json('$.data.records[0].serialNumber', 'serialNumber')
# inter.post_json('/manager/store-table/add', '[{"tableName":"a4","capacity":"1","storeId":"{serialNumber}"}]')
# inter.assert_equals("msg","成功。")

# # 餐桌分页查询
# inter.post_json('/manager/store-table/page', '{"current":  1,"size": 10,"storeId":1569584669147209730,"tableName": null}')
# inter.assert_equals('code', '0000')

# 新增菜单
# inter.post_json("/manager/store/page", '{"size":10,"current":1,"cityId":"","name":"测试门店-zwx"}')
# inter.save_json('$.data.records[0].serialNumber', 'serialNumber')
# inter.post_json('/manager/product-menu/insert-store-product-menu',
#                 '{"name": "11221","serialNumber": "{serialNumber}","orderTypeId": "1","enabled": 0}')
# # 提取菜单id
# inter.save_json("$.data.id", "id")
#
# # 保存菜单的菜品
# inter.post_json("/manager/product-menu/save-products",
#                 '[{"id":null,"productMenuId":"{id}","name":"111","icon":null,"sort":1,"products":[{"productId":"1567434902541041666","productName":"极鲜鸡汁炒菜心","sort":160,"specs":[{"id":"1567434913442037762","productId":"1567434902541041666","specId":"1","price":0.01,"cost":0.01,"defaulted":1,"specName":"系统默认规格","typeId":-1,"typeName":"","code":null,"enabled":1}],"specialCooks":[],"toppings":[],"tags":[]}]}]')
# #
# # 删除菜单
# inter.post_json("/manager/product-menu/delete", '{"id":"{id}"}')

# 新增餐桌
# 门店id(long)      餐桌名称(string)     容纳人数(int)
# storeId为必填项   tableName为必填项   capacity为非必填

# 反向用例
# storeId为空,不传,错误的,为null
# inter.post_json('/manager/store-table/add', '[{"tableName":"a1","capacity":"1","storeId":""}]')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/add', '[{"tableName":"a1","capacity":"1"}]')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/add', '[{"tableName":"a4","capacity":"1","storeId":"15695846691472097301"}]')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/add', '[{"tableName":"a5","capacity":"1","storeId":null}]')
# inter.assert_equals("msg","参数验证失败。")

# # tableName为空，不传,为null
# inter.post_json('/manager/store-table/add', '[{"tableName":"","capacity":"1","storeId":"1569584669147209730"}]')
# inter.assert_equals("msg","成功。")
# inter.post_json('/manager/store-table/add', '[{"capacity":"1","storeId":"1569584669147209730"}]')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/add', '[{"tableName":null,"capacity":"1","storeId":"1569584669147209730"}]')
# inter.assert_equals("msg","参数验证失败。")

# # 容纳人数字段不传，为空
# inter.post_json('/manager/store-table/add', '[{"tableName":"a2","storeId":"1569584669147209730"}]')
# inter.assert_equals("msg","成功。")
# inter.save_json("$.data[0].id",'newid')
# inter.post_json('/manager/store-table/del', 'id={newid}')
# inter.post_json('/manager/store-table/add', '[{"tableName":"a3","capacity":"","storeId":"1569584669147209730"}]')
# inter.assert_equals("msg","成功。")
# inter.save_json("$.data[0].id",'newid')
# inter.post_json('/manager/store-table/del', 'id={newid}')

# # 提取餐桌id
# inter.save_json("$.data[0].id",'newid')
# inter.save_json("$.data[0].tableName",'tableName')
# # 下载点餐码
# inter.get("/manager/store-table/downloadQrCode?storeId=1569584669147209730&tableId={newid}&tableName={tableName}")
# inter.assert_equals("msg","成功。")

# # 修改餐桌
# # 修改餐桌名称
# inter.post_json('/manager/store-table/update',
#                 '{"id": "{newid}","capacity": 1,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","成功。")

# # # 修改餐桌所属门店

# # 修改餐桌的容纳人数
# inter.post_json('/manager/store-table/update',
#                 '{"id": "{newid}","capacity": 11,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","成功。")

# # id为空字符串 id为null id错误 id字段不传
# inter.post_json('/manager/store-table/update',
#                 '{"id": "","capacity": 1,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","id不能为空")
# inter.post_json('/manager/store-table/update',
#                 '{"id": null,"capacity": 1,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","id不能为空")
# inter.post_json('/manager/store-table/update',
#                 '{"id": "1233","capacity": 1,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/update',
#                 '{"capacity": 1,"storeId": 1569584669147209730,"tableName": "A01"}')
# inter.assert_equals("msg","参数验证失败。")

# # 删除餐桌
# inter.post_json('/manager/store-table/del', 'id={newid}')
# inter.assert_equals('code', '0000')
# # storeId字段
# # storeId为空字符# storeId为null# storeId为错误值# storeId字段不传
# inter.post_json('/manager/store-table/del', 'id=')
# inter.assert_equals("msg","id不能为空")
# inter.post_json('/manager/store-table/del', 'id=null')
# inter.assert_equals("msg","id不能为空")
# inter.post_json('/manager/store-table/del', 'id=123213')
# inter.assert_equals("msg","参数验证失败。")
# inter.post_json('/manager/store-table/del', '')
# inter.assert_equals("msg","参数验证失败。")

